package com.hyh.eblog.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyh.eblog.service.*;
import com.hyh.eblog.shiro.AccountProfile;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Summerday
 */
public class BaseController {

    @Autowired
    HttpServletRequest request;

    @Autowired
    PostService postService;

    @Autowired
    CommentService commentService;

    @Autowired
    UserMessageService userMessageService;

    @Autowired
    UserCollectionService userCollectionService;

    @Autowired
    CategoryService categoryService;

    public Page getPage(){
        int pn = ServletRequestUtils.getIntParameter(request,"pn",1);//current
        int size = ServletRequestUtils.getIntParameter(request,"size",5);//size
        return new Page(pn, size);
    }

    protected AccountProfile getProfile(){
        return (AccountProfile) SecurityUtils.getSubject().getPrincipal();
    }

    protected Long getProfileId(){
        return getProfile().getId();
    }
}
